home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / SetupScalers68k.c < prev    next >
C/C++ Source or Header  |  1994-09-22  |  5KB  |  231 lines

  1. #include "WolfDef.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. LongWord ScaleDiv[2048];
  6.  
  7. /**********************************
  8.  
  9.     Create the compiled scalers
  10.  
  11. **********************************/
  12.  
  13. Boolean SetupScalers(void)
  14. {
  15.     Word i;
  16.         
  17.     if (!ScaleDiv[1]) {        /* Divide table inited already? */
  18.         i = 1;
  19.         do {
  20.             ScaleDiv[i] = 0x400000UL/(LongWord)i;        /* Get the recipocal for the scaler */
  21.         } while (++i<2048);
  22.     }
  23.     MaxScaler = 2048;
  24.     return TRUE;
  25. }
  26.  
  27. void ReleaseScalers(void)
  28. {
  29. }
  30.  
  31. /**********************************
  32.  
  33.     Draw a vertical line with a scaler
  34.     (Used for WALL drawing)
  35.     
  36. **********************************/
  37.  
  38. void ScaleGlue(void *a,LongWord scale,void *c,LongWord d,LongWord e,LongWord f,LongWord g);
  39.     
  40. #if 0
  41. void IO_ScaleWallColumn(Word x,Word scale,LongWord column)
  42. {
  43.     LongWord TheFrac;
  44.     LongWord TheInt;
  45.     LongWord y;
  46.     Byte *ArtStart;
  47.     
  48.     if (scale) {        /* Uhh.. Don't bother */
  49.         TheFrac = ScaleDiv[scale];
  50.         scale*=2;
  51.         ArtStart = &ArtData[(column>>7)&0x3f][(column&127)<<7];
  52.         if (scale<VIEWHEIGHT) {
  53.             y = (VIEWHEIGHT-scale)/2;
  54.             TheInt = TheFrac>>24;
  55.             TheFrac <<= 8;
  56.             ScaleGlue(ArtStart,scale,
  57.                 &VideoPointer[(y*VideoWidth)+x],
  58.                 TheFrac,
  59.                 TheInt,
  60.                 VideoWidth,
  61.                 0
  62.             );
  63.             return;
  64.         }
  65.         y = (scale-VIEWHEIGHT)/2;        /* How manu lines to remove */
  66.         y = y*TheFrac;
  67.         TheInt = TheFrac>>24;
  68.         TheFrac <<= 8L;
  69.         ScaleGlue(&ArtStart[y>>24L],VIEWHEIGHT,
  70.             &VideoPointer[x],
  71.             TheFrac,
  72.             TheInt,
  73.             VideoWidth,
  74.             y<<8L
  75.         );
  76.     }
  77. }
  78. #endif
  79.  
  80. /**********************************
  81.  
  82.     Draw a vertical line with a masked scaler
  83.     (Used for SPRITE drawing)
  84.     
  85. **********************************/
  86.  
  87. typedef struct {
  88.     unsigned short Topy;
  89.     unsigned short Boty;
  90.     unsigned short Shape;
  91. } SpriteRun;
  92.  
  93. void SpriteGlue(Byte *a,LongWord b,Byte *c,Word d,Word e);
  94. /*
  95. SGArtStart    EQU    A0        ;Pointer to the 6 byte run structure
  96. SGFrac    EQU    D2        ;Pointer to the scaler
  97. SGInteger    EQU D3        ;Pointer to the video
  98. SGScreenPtr    EQU    A1        ;Pointer to the run base address
  99. SGCount    EQU D6
  100. SGDelta    EQU    D4
  101. */
  102. void IO_ScaleMaskedColumn(Word x,Word scale,unsigned short *CharPtr,Word column) 
  103. {
  104.     Byte * CharPtr2;
  105.     int Y1,Y2;
  106.     Byte *Screenad;
  107.     SpriteRun *RunPtr;
  108.     LongWord TheFrac;
  109.     Word RunCount;
  110.     Word TopY;
  111.     Word Index;
  112.     LongWord Delta;
  113.     
  114.     if (!scale) {
  115.         return;
  116.     }
  117.     CharPtr2 = (Byte *) CharPtr;
  118.     TheFrac = ScaleDiv[scale];        /* Get the scale fraction */ 
  119.     RunPtr = (SpriteRun *) &CharPtr[CharPtr[column+1]/2];    /* Get the offset to the RunPtr data */
  120.     Screenad = &VideoPointer[x];        /* Set the base screen address */;
  121.     TopY = (VIEWHEIGHT/2)-scale;        /* Number of pixels for 128 pixel shape */
  122.  
  123.     while (RunPtr->Topy != (unsigned short) -1) {        /* Not end of record? */
  124.         Y1 = (LongWord)scale*RunPtr->Topy/128+TopY;
  125.         if (Y1<(int)VIEWHEIGHT) {        /* Clip top? */
  126.         Y2 = (LongWord)scale*RunPtr->Boty/128+TopY;
  127.         if (Y2>0) {
  128.         
  129.         if (Y2>(int)VIEWHEIGHT) {
  130.             Y2 = VIEWHEIGHT;
  131.         }
  132.         Index = RunPtr->Shape+(RunPtr->Topy/2);
  133.         Delta = 0;
  134.         if (Y1<0) {
  135.             Delta = (LongWord)(0-Y1)*TheFrac;
  136.             Index += (Delta>>16);
  137.             Y1 = 0;
  138.         }
  139.         RunCount = Y2-Y1;        /* How many lines to draw?*/
  140.         if (RunCount) {
  141.             SpriteGlue(
  142.             &CharPtr2[Index],    /* Pointer to art data */
  143.             TheFrac,                /* Fixed point fractional value */ 
  144.             &Screenad[YTable[Y1]],            /* Pointer to screen */
  145.             RunCount,            /* Number of lines to draw */
  146.             Delta                    /* Delta value */
  147.             );
  148.         }
  149.         }
  150.         } 
  151.         RunPtr++;                        /* Next record */
  152.     }    
  153. }
  154.  
  155. /**********************************
  156.  
  157.     Draw an automap tile
  158.     
  159. **********************************/
  160.  
  161. Byte *SmallFontPtr;
  162.  
  163. void DrawSmall(Word x,Word y,Word tile)
  164. {
  165.     Byte *Screenad;
  166.     Byte *ArtStart;
  167.     Word Width,Height;
  168.  
  169.     if (!SmallFontPtr) {
  170.         return;
  171.     }    
  172.     x*=16;
  173.     y*=16;
  174.     Screenad = &VideoPointer[YTable[y]+x];
  175.     ArtStart = &SmallFontPtr[tile*(16*16)];
  176.     Height = 0;
  177.     do {
  178.         Width = 16;
  179.         do {
  180.             Screenad[0] = ArtStart[0];
  181.             ++Screenad;
  182.             ++ArtStart;
  183.         } while (--Width);
  184.         Screenad+=VideoWidth-16;
  185.     } while (++Height<16);
  186. }
  187.  
  188. void MakeSmallFont(void)
  189. {
  190.     Word i,j,Width,Height;
  191.     Byte *DestPtr,*ArtStart;
  192.     Byte *TempPtr;
  193.     
  194.     SmallFontPtr = AllocSomeMem(16*16*65);
  195.     if (!SmallFontPtr) {
  196.         return;
  197.     }
  198.     memset(SmallFontPtr,0,16*16*65);        /* Erase the font */
  199.     i = 0;
  200.     DestPtr = SmallFontPtr;
  201.     do {
  202.         ArtStart = &ArtData[i][0];
  203.         if (!ArtStart) {
  204.             DestPtr+=(16*16);
  205.         } else {
  206.             Height = 0;
  207.             do {
  208.                 Width = 16;
  209.                 j = Height*8;
  210.                 do {
  211.                     DestPtr[0] = ArtStart[j];
  212.                     ++DestPtr;
  213.                     j+=(WALLHEIGHT*8);
  214.                 } while (--Width);
  215.             } while (++Height<16);
  216.         }
  217.     } while (++i<64);
  218.     TempPtr = LoadAResource(MyBJFace);
  219.     memcpy(DestPtr,TempPtr,16*16);
  220.     ReleaseAResource(MyBJFace);
  221. }
  222.  
  223. void KillSmallFont(void)
  224. {    
  225.     if (SmallFontPtr) {
  226.         FreeSomeMem(SmallFontPtr);
  227.         SmallFontPtr=0;        
  228.     }
  229. }
  230.  
  231.